
import java.util.HashMap;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str1 = sc.next();
        String str2 = sc.next();
        String[] strs = new String[n];
        for (int i = 0; i < n; i++) {
            strs[i] = sc.next();
        }
        System.out.println(A(str1,str2,strs));
    }
        public static int A(String str1, String str2, String[] strs) {
            HashMap<String, Integer> ha = new HashMap<>();
            if (str1 == null || str2 == null) {
                return -1;
            }
            int res = Integer.MAX_VALUE;
            for (int i = 0 ; i < strs.length ; i++){
                ha.put(strs[i] , i);
                if (ha.containsKey(str1)&& ha.containsKey(str2)){
                    res = Math.abs(ha.get(str1) - ha.get(str2));
                }
            }
            return res;
        }

    }









